package com.example.baseexercises.Redis;

/**
 * @author: 辛之所想
 * @create: 2025-11-15 20:43
 * @description:
 **/
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redisHash")
@Tag(name = "RedisHash",description = "RedisHash操作")
public class RedisHash {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/redisHashTest")
    @Operation(summary = "RedisSet测试")
    public String redisHashTest() {
        set("redisHashKey", "redisHashField1", "redisHashValue1");
        return get("redisHashKey","redisHashField1");
    }
    public void set(String key, String field, String value) {
        stringRedisTemplate.opsForHash().put(key,field,value);
    }

    public String get(String key, String field) {
        return (String) stringRedisTemplate.opsForHash().get(key,field);
    }
}
